package com.next.androidintentlibrary;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.app.Context;

public class TimerIntents {
    private Context context;
    private Intent intent;

    private TimerIntents(Context context)
    {
        this.context = context;
    }

    public static TimerIntents from(Context context)
    {
        return new TimerIntents(context);
    }

    public TimerIntents createTimer(String subject, int seconds, boolean skipUi)
    {
        intent = new Intent();
        intent.setAction("android.intent.action.SET_TIMER");
        intent.setParam("android.intent.extra.alarm.MESSAGE", subject);
        intent.setParam("android.intent.extra.alarm.LENGTH", seconds);
        intent.setParam("android.intent.extra.alarm.SKIP_UI", skipUi);
        return this;
    }

    public Intent build()
    {
        return intent;
    }

    private void startAbility(Intent intent)
    {
        if (!(context instanceof Ability))
        {
            intent.addFlags(Intent.FLAG_ABILITY_NEW_MISSION);
        }
        context.startAbility(intent,0);
    }

    public void show()
    {
        startAbility(build());
    }
}
